<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="全库唯一码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'puid', validatorRules.puid]" placeholder="请输入全库唯一码"></a-input>
        </a-form-item>
        <a-form-item label="采购方总部编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'purchaserhqcode', validatorRules.purchaserhqcode]" placeholder="请输入采购方总部编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'suppliercode', validatorRules.suppliercode]" placeholder="请输入供应商编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'suppliername', validatorRules.suppliername]" placeholder="请输入供应商名称"></a-input>
        </a-form-item>
        <a-form-item label="生产工单编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'wono', validatorRules.wono]" placeholder="请输入生产工单编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商生产订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ipono', validatorRules.ipono]" placeholder="请输入供应商生产订单编号"></a-input>
        </a-form-item>
        <a-form-item label="品类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'categorycode', validatorRules.categorycode]" placeholder="请输入品类编码"></a-input>
        </a-form-item>
        <a-form-item label="种类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'subclasscode', validatorRules.subclasscode]" placeholder="请输入种类编码"></a-input>
        </a-form-item>
        <a-form-item label="厂家物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialscode', validatorRules.materialscode]" placeholder="请输入厂家物料编码"></a-input>
        </a-form-item>
        <a-form-item label="厂家物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsdescription', validatorRules.materialsdescription]" placeholder="请输入厂家物料描述"></a-input>
        </a-form-item>
        <a-form-item label="物料批次" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'materialsbatch', validatorRules.materialsbatch]" placeholder="请输入物料批次"></a-input>
        </a-form-item>
        <a-form-item label="生产数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'amount', validatorRules.amount]" placeholder="请输入生产数量"></a-input>
        </a-form-item>
        <a-form-item label="计量单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'unit', validatorRules.unit]" placeholder="请输入计量单位"></a-input>
        </a-form-item>
        <a-form-item label="计划开始日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择计划开始日期" v-decorator="[ 'planstartdate', validatorRules.planstartdate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="计划完成日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择计划完成日期" v-decorator="[ 'planfinishdate', validatorRules.planfinishdate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="实际开始日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择实际开始日期" v-decorator="[ 'actualstartdate', validatorRules.actualstartdate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="实际完成日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择实际完成日期" v-decorator="[ 'actualfinishdate', validatorRules.actualfinishdate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="工单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'wostatus', validatorRules.wostatus]" placeholder="请输入工单状态"></a-input>
        </a-form-item>
        <a-form-item label="实物ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'entitycode', validatorRules.entitycode]" placeholder="请输入实物ID"></a-input>
        </a-form-item>
        <a-form-item label="工艺路线编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processrouteno', validatorRules.processrouteno]" placeholder="请输入工艺路线编码"></a-input>
        </a-form-item>
        <a-form-item label="processrevision" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processrevision', validatorRules.processrevision]" placeholder="请输入processrevision"></a-input>
        </a-form-item>
        <a-form-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'datasource', validatorRules.datasource]" placeholder="请输入数据来源"></a-input>
        </a-form-item>
        <a-form-item label="来源数据创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择来源数据创建时间" v-decorator="[ 'datasourcecreatetime', validatorRules.datasourcecreatetime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="数据拥有方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ownerid', validatorRules.ownerid]" placeholder="请输入数据拥有方"></a-input>
        </a-form-item>
        <a-form-item label="数据可见方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'openid', validatorRules.openid]" placeholder="请输入数据可见方"></a-input>
        </a-form-item>
        <a-form-item label="逻辑删除" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'isdeleted', validatorRules.isdeleted]" placeholder="请输入逻辑删除"></a-input>
        </a-form-item>
        <a-form-item label="更新时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'modifytime', validatorRules.modifytime]" placeholder="请输入更新时间"></a-input>
        </a-form-item>
        <a-form-item label="产品型号规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'modelspec', validatorRules.modelspec]" placeholder="请输入产品型号规格"></a-input>
        </a-form-item>
        <a-form-item label="状态表示" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入状态表示"></a-input>
        </a-form-item>
        <a-form-item label="错误信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'message', validatorRules.message]" placeholder="请输入错误信息"></a-input>
        </a-form-item>
        <a-form-item label="本条数据是新增/更新" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'status', validatorRules.status]" placeholder="请输入本条数据是新增/更新"></a-input>
        </a-form-item>
        <a-form-item label="全局流水号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'transno', validatorRules.transno]" placeholder="请输入全局流水号"></a-input>
        </a-form-item>
        <a-form-item label="预留字段1" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark1', validatorRules.remark1]" placeholder="请输入预留字段1"></a-input>
        </a-form-item>
        <a-form-item label="预留字段2" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark2', validatorRules.remark2]" placeholder="请输入预留字段2"></a-input>
        </a-form-item>
        <a-form-item label="预留字段3" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark3', validatorRules.remark3]" placeholder="请输入预留字段3"></a-input>
        </a-form-item>
        <a-form-item label="预留字段4" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark4', validatorRules.remark4]" placeholder="请输入预留字段4"></a-input>
        </a-form-item>
        <a-form-item label="预留字段5" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remark5', validatorRules.remark5]" placeholder="请输入预留字段5"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "EipWorkOrderModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        puid:{rules: [{ required: true, message: '请输入全库唯一码!' }]},
        purchaserhqcode:{rules: [{ required: true, message: '请输入采购方总部编码!' }]},
        suppliercode:{rules: [{ required: true, message: '请输入供应商编码!' }]},
        suppliername:{rules: [{ required: true, message: '请输入供应商名称!' }]},
        wono:{rules: [{ required: true, message: '请输入生产工单编码!' }]},
        ipono:{rules: [{ required: true, message: '请输入供应商生产订单编号!' }]},
        categorycode:{rules: [{ required: true, message: '请输入品类编码!' }]},
        subclasscode:{rules: [{ required: true, message: '请输入种类编码!' }]},
        materialscode:{rules: [{ required: true, message: '请输入厂家物料编码!' }]},
        materialsdescription:{},
        materialsbatch:{},
        amount:{rules: [{ required: true, message: '请输入生产数量!' }]},
        unit:{rules: [{ required: true, message: '请输入计量单位!' }]},
        planstartdate:{rules: [{ required: true, message: '请输入计划开始日期!' }]},
        planfinishdate:{rules: [{ required: true, message: '请输入计划完成日期!' }]},
        actualstartdate:{},
        actualfinishdate:{},
        wostatus:{rules: [{ required: true, message: '请输入工单状态!' }]},
        entitycode:{},
        processrouteno:{},
        processrevision:{},
        datasource:{rules: [{ required: true, message: '请输入数据来源!' }]},
        datasourcecreatetime:{rules: [{ required: true, message: '请输入来源数据创建时间!' }]},
        ownerid:{},
        openid:{},
        isdeleted:{rules: [{ required: true, message: '请输入逻辑删除!' }]},
        modifytime:{},
        modelspec:{},
        ioflag:{},
        message:{},
        status:{},
        transno:{},
        remark1:{},
        remark2:{},
        remark3:{},
        remark4:{},
        remark5:{},
        },
        url: {
          add: "/pg/eipWorkOrder/add",
          edit: "/pg/eipWorkOrder/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'puid','purchaserhqcode','suppliercode','suppliername','wono','ipono','categorycode','subclasscode','materialscode','materialsdescription','materialsbatch','amount','unit','planstartdate','planfinishdate','actualstartdate','actualfinishdate','wostatus','entitycode','processrouteno','processrevision','datasource','datasourcecreatetime','ownerid','openid','isdeleted','modifytime','modelspec','ioflag','message','status','transno','remark1','remark2','remark3','remark4','remark5'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'puid','purchaserhqcode','suppliercode','suppliername','wono','ipono','categorycode','subclasscode','materialscode','materialsdescription','materialsbatch','amount','unit','planstartdate','planfinishdate','actualstartdate','actualfinishdate','wostatus','entitycode','processrouteno','processrevision','datasource','datasourcecreatetime','ownerid','openid','isdeleted','modifytime','modelspec','ioflag','message','status','transno','remark1','remark2','remark3','remark4','remark5'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>